<%--
  Created by IntelliJ IDEA.
  User: 1234
  Date: 2018/5/2
  Time: 20:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="/static/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" type="text/css" href="/static/css/admin.css">
</head>
<body>
<div style="padding: 15px;">
    <form class="bs-example bs-example-form">
        <table class="table">
            <tbody><tr>
                <td width="100">原始密码：</td>
                <td width="450">
                    <input type="password" class="form-control" name="oldpass" placeholder="请输入原始密码">
                </td>
            </tr>
            <tr>
                <td>新的密码：</td>
                <td><input type="password" class="form-control" name="newpass" placeholder="请输入新密码"></td>
            </tr>
            <tr>
                <td>确认密码：</td>
                <td><input type="password" class="form-control" name="repass" placeholder="请再次输入新密码"></td>
            </tr>
            </tbody></table>
        <button class="btn btn-primary btn-lg btn-block" type="button" onclick="EditPass()">提交保存</button>
    </form>
</div>
</body>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/layer/layer.js"></script>
<script>
    function EditPass(){
        var oldpass=$('input[name=oldpass]').val(),
            newpass=$('input[name=newpass]').val(),
            repass=$('input[name=repass]').val(),
            data;
        if(!oldpass  || !/^[\w\W]{6,30}$/.test(oldpass)){
            layer.msg('密码长度应为6-30个字符之间',{icon: 2,time:1000});
            $('input[name=oldpass]').focus();
            return false;
        }
        if(!newpass  || !/^[\w\W]{6,30}$/.test(newpass)){
            layer.msg('密码长度应为6-30个字符之间',{icon: 2,time:1000});
            $('input[name=newpass]').focus();
            return false;
        }
        if(newpass==oldpass){
            layer.msg('与原始密码一致',{icon: 2,time:1000});
            $('input[name=newpass]').focus();
            return false;
        }
        if(repass!=newpass){
            layer.msg('再次输入密码不一致',{icon: 2,time:1000});
            $('input[name=repass]').focus();
            return false;
        }
        data={pwd:oldpass,newPwd:newpass,_method:"put"};
        $.ajax({
            type:'post',
            url : "/user/fm",
            data:  data,
            success: function(json){
                if(json.status==2){
                    layer.msg(json.fixMsg,{icon: 2,time:1000});
                    $('input[type=password]').val("");
                }else{
                    layer.msg(json.fixMsg,{icon: 1,time:2000});
                    if(json.status==1)
                        setTimeout(function(){top.location.href='/p/user/login';},1000)
                }
            },
            error:function (){
                layer.msg('网络连接失败',{icon: 5,area: ['', '15%'],time:1000});
            }
        });
    }
</script>
</html>
